package ajobs.websocket.main;

import ajobs.websocket.main.dto.MessageRequest;
import ajobs.websocket.main.dto.MessageResponse;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Controller
public class WebSocketController {

    // 处理客户端发送到 /app/chat 的消息
    @MessageMapping("/chat")
    @SendTo("/topic/messages") // 将返回的消息广播到 /topic/messages （客户端订阅）
    public MessageResponse sendMessage(MessageRequest request) {
        return new MessageResponse(request.getContent());
    }
}